#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "libcytovision.h"

/*! \brief Convert a BMP to RAW
 * \param filename_src Filename to be read on conversion
 * \param filename_dst Filename to be writen
 * Convert a BMP file to RAW file used by cytovision
 * \retval 0 Ok
 * \retval -1 Cannot open src filename
 * \retval -2 Cannot open dst filename
*/
int cytovision_bmp2raw(char *filename_src, char *filename_dst) {
  int fd1,fd2,size;
  char buf[1024];

  fd1=open(filename_src,O_RDONLY);
  fd2=open(filename_src,O_RDWR);

  lseek(fd1,1078,SEEK_SET); // Skip BMP header

  while((size=read(fd1,buf,sizeof(buf)))>0)
    write(fd2,buf,size);

  close(fd1);
  close(fd2);
  return 0;
}
